package pl.edu.mimuw.irs.rcp.view.figure;

import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.XYLayout;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.swt.graphics.Font;

import pl.edu.mimuw.irs.rcp.controller.editor.workflow.part.AbstractNodeEditPart.NodeShape;
import pl.edu.mimuw.irs.rcp.util.enums.EnumFont;

public class SimulationPlaceShape extends PlaceShape {

	// *** Attributes

	private Label label;
	private int tokens;
	public Label getLabel() {
		return label;
	}
	public void setLabel(Label label) {
		if (this.getLabel() != null) this.remove(getLabel());
		//label.setTextPlacement(PositionConstants.SOUTH);
		if (label != null) add(label);
		label.setBounds(this.getBounds());
		//setSize(getPreferredSize());
		this.label = label;
	}
	public int getTokens() {
		return tokens;
	}
	public void setTokens(int tokens) {
		this.tokens = tokens;
		if (tokens == 0) {
			getLabel().setText(null);
		} else {
			getLabel().setText(new Integer(tokens).toString());
			label.setBounds(this.getBounds());
		}
	}
	
	// *** Constructors
	
	public SimulationPlaceShape() {
		Label label = new Label("");
		Font font = EnumFont.ARIAL_8_BOLD.getInstance();
		
		// XXX : zrobić poniższe jak należy
		Dimension size = new Dimension(NodeShape.TGPLACE.getWidth(), NodeShape.TGPLACE.getHeight());
		setMinimumSize(size);
		setMaximumSize(size);
		setPreferredSize(size);
		
		XYLayout layout = new XYLayout();
	    //layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
	    //layout.setStretchMinorAxis(false);
	    //layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
	    //layout.setSpacing(2);
	    //layout.setVertical(true);
		

	    setOpaque(true);
	    setLayoutManager(layout);

		label.setFont(font);
		label.setTextAlignment(PositionConstants.CENTER);
        label.setTextPlacement(PositionConstants.CENTER);
		label.setBounds(this.getBounds());
		setLabel(label);
	}
}
